package com.elitesland.system.repo;

import cn.hutool.core.util.StrUtil;
import com.elitesland.system.entity.QSysUdcDO;
import com.elitesland.system.param.SysUdcQueryParam;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import lombok.val;
import org.apache.commons.collections4.CollectionUtils;


/**
 * <p>
 * 功能说明
 * </p>
 *
 * @author Mir
 * @date 2020/6/29
 */
public class SysUdcRepoProc {

    public static Predicate where(SysUdcQueryParam param) {
        val sysUdc = QSysUdcDO.sysUdcDO;

        com.querydsl.core.types.Predicate predicate = sysUdc.isNotNull().or(sysUdc.isNull());
        predicate = StrUtil.isBlank(param.getDomainCode()) ? predicate : ExpressionUtils.and(predicate, sysUdc.domainCode.like("%" + param.getDomainCode() + "%"));
        predicate = StrUtil.isBlank(param.getUdcCode()) ? predicate : ExpressionUtils.and(predicate, sysUdc.udcCode.like("%" + param.getUdcCode() + "%"));
        predicate = StrUtil.isBlank(param.getUdcVal()) ? predicate : ExpressionUtils.and(predicate, sysUdc.udcVal.like("%" + param.getUdcVal() + "%"));
        predicate = StrUtil.isBlank(param.getValDesc()) ? predicate : ExpressionUtils.and(predicate, sysUdc.valDesc.like("%" + param.getValDesc() + "%"));
        /****20201110  金小康   start ******/
        predicate = StrUtil.isBlank(param.getUdcName()) ? predicate : ExpressionUtils.and(predicate, sysUdc.udcName.like("%" + param.getUdcName() + "%"));
        predicate = StrUtil.isBlank(param.getUdcDesc()) ? predicate : ExpressionUtils.and(predicate, sysUdc.valDesc.like("%" + param.getUdcDesc() + "%"));
        /****20201110  金小康   end ******/
        predicate = CollectionUtils.isEmpty(param.getCodes()) ? predicate : ExpressionUtils.and(predicate, sysUdc.udcCode.in(param.getCodes()));

        return predicate;

    }
    public static Predicate where2(SysUdcQueryParam param) {
        val sysUdc = QSysUdcDO.sysUdcDO;

        com.querydsl.core.types.Predicate predicate = sysUdc.isNotNull().or(sysUdc.isNull());
        predicate = StrUtil.isBlank(param.getDomainCode()) ? predicate : ExpressionUtils.and(predicate, sysUdc.domainCode.eq(param.getDomainCode() ));
        predicate = StrUtil.isBlank(param.getUdcCode()) ? predicate : ExpressionUtils.and(predicate, sysUdc.udcCode.eq( param.getUdcCode() ));
        predicate = StrUtil.isBlank(param.getUdcVal()) ? predicate : ExpressionUtils.and(predicate, sysUdc.udcVal.like("%" + param.getUdcVal() + "%").or(sysUdc.valDesc.like("%" + param.getUdcVal() + "%")));


        return predicate;

    }


    public static Predicate where3(SysUdcQueryParam param) {
        val sysUdc = QSysUdcDO.sysUdcDO;

        com.querydsl.core.types.Predicate predicate = sysUdc.isNotNull().or(sysUdc.isNull());
        predicate = StrUtil.isBlank(param.getDomainCode()) ? predicate : ExpressionUtils.and(predicate, sysUdc.domainCode.eq(param.getDomainCode() ));
        predicate = StrUtil.isBlank(param.getUdcCode()) ? predicate : ExpressionUtils.and(predicate, sysUdc.udcCode.eq( param.getUdcCode() ));
        predicate = StrUtil.isBlank(param.getUdcVal()) ? predicate : ExpressionUtils.and(predicate, sysUdc.udcVal.like(param.getUdcVal() + "%"));


        return predicate;

    }
}
